{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "40dee947",
   "metadata": {},
   "outputs": [],
   "source": [
    "#从python模块中调出datetime模块\n",
    "from datetime import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "87f264cc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "39"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.today().minute"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb2a1d68",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This minute seems a little odd.\n",
      "This minute seems a little odd.\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "import random\n",
    "import time\n",
    "# 课本上的代码（第一章，在奇数中选择特定的时间点）\n",
    "odds=[1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "# range(5)决定了for循环的次数，即for循环过程的执行次数\n",
    "for i in range(5):#for循环正确的迭代5次;固定的次数\n",
    "    #由print(i)这件案例我们明白了，在循环过程中，变量名虽然没变，但是值是动态变化的\n",
    "    right_this_minute = datetime.today().minute\n",
    "    if right_this_minute in odds:\n",
    "        print(\"This minute seems a little odd.\")\n",
    "    else:\n",
    "        print(\"Not an odd minute.\")\n",
    "    #增加等待时间\n",
    "    wait_time=random.randint(1,60)#等待的时间生成指定范围的一个随机整数\n",
    "    time.sleep(wait_time)#因为只导入import time一个模块，既需要用模块名对这个模块中的函数的使用加以限定"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "95e40964",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
